<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
include_once( "member/proc_betin.php" );
$ui = new UI();
$tpl = new Template2();
$tpl->load(array("news" => "news.htm"));
$conf = new Config();
$news = $conf->Get("news_th");
if ($news == "")
{
    $news = $conf->Get("news");
}
else
{
    $news = "<font color=red>" . $news . "</font>&#12288;" . $conf->Get("news");
}
$tpl->set("newsmessage", $news);
$tpl->show("news");
$tpl->set("account", $curruser['account']);
if ($curruser['enabled'] == 0 || $curruser['enabled'] == 2)
{
    $ui->showErrorPage("<p class=error>帐号已被暂停使用</p>");
    exit();
}
$rs = getdb("select * from lotto where open>='" . date("Y-m-d") . "' order by open");
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>目前没有可以下注期数！</p>");
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$lotto_ns = $rs->f['n1'] + $rs->f['n2'] + $rs->f['n3'] + $rs->f['n4'] + $rs->f['n5'] + $rs->f['n6'];
$conf = new Config();
$stopbet = $conf->get("waitbet");
if (date("Y-m-d") < $open)
{
    exit();
}
else if (date("Y-m-d") == $open)
{
    if ($stopbet <= date("Hi") || 0 < $lotto_ns)
    {
        $ui->showErrorPage("<p>下注期数：" . d3($round) . "<br>开奖日：" . $open . "</p>" . "<p class=error>已经截止下注！</p>");
        exit();
    }
    else if (date("Hi") <= $conf->get("startbet"))
    {
        exit();
    }
}
$t1 = strtotime($open . " " . $stopbet);
$tpl->Set("timestap", $t1 - systime());
$tpl->set("open", $open);
$tpl->set("round", d3($round));
$tpl->set("lotto_id", $lotto_id);
$tpl->set("account", $curruser['account']);
$tpl->set("amount", $curruser['amount']);
$disk = $g_disk_code[getUserValidDisk($curruser)];
$rates = getdb("select * from rate1" . $disk . " where lotto_id=" . $lotto_id);
if ($rates->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$betmin = $conf->get("betmin");
$tpl->set("min", $betmin);
$betmax = $conf->get("betmax");
$tpl->set("max", $betmax);
$tpl->set("max_str", $betmax);
$rs = getdb("select amount_6h from k_user_bet where user_id=" . $curruser['id'] . " and lotto_id=" . $lotto_id);
$usedamount = $rs->f[0] ? $rs->f[0] : 0;
$rs->close();
$limit = array();
$limit[21] = GetAmountInfo(21);
$limit[22] = GetAmountInfo(22);
$limit[37] = GetAmountInfo(37);
$limit[38] = GetAmountInfo(38);
$limit[34] = GetAmountInfo(34);
$limit[35] = GetAmountInfo(35);
$ok = isset($_POST['ok']);
if ($ok)
{
    echo "<body>";
}
else
{
    echo "<body onload='StartFocus()'>";
}
$bets = isset($_GET['bets']) ? $_GET['bets'] : 1;
echo "<form action=\"op.php?op=member&fp=proc19&bets={$bets}\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
echo "<input type=hidden name=ok value=1>";
echo "<input type=hidden name=disk value=" . strpos(" abcd", $disk) . ">";
$waittime = 2000;
$betcount = 0;
$total = 0;
$tmp = "";
$usemaxamount = $curruser['usemaxamount'];
$ok21 = 0;
$u2 = get_user($curruser['prev_id']);
$u3 = get_user($u2['prev_id']);
$u4 = get_user($u3['prev_id']);
$u5 = get_user($u4['prev_id']);
$i = 1;
while ($i <= 12)
{
    if (isset($_POST["r21_" . $i]))
    {
        $money = intval($_POST["r21_" . $i]);
        $bettype = $bets == 1 ? 21 : 37;
        if (0 < $money)
        {
            if (!$ok)
            {
                $ok21 = 1;
                echo "<input type=hidden name=r21_{$i} value=" . $money . ">";
            }
            ++$betcount;
            $err = 0;
            $val = $i;
            $tmp .= "<tr class=td2>";
            $tmp .= "<td>" . $g_betname[$bettype] . "</td>";
            $tmp .= "<td>" . $g_chinayear[$val] . "</td>";
            $sub_rates = get_subs_rates($u5['id'], $lotto_id, 21, $val);
            $rate = $rates->f["r{$bettype}_" . $val] - $sub_rates;
            $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
            $tmp .= "<td align=right>" . $money . "</td>";
            if ($ok)
            {
                $tmp .= "<td>";
                if ($money < $betmin)
                {
                    $tmp .= "<font color=red>小於最小限额";
                    $waittime += 200;
                }
                else if ($curruser['balance'] < $money)
                {
                    $tmp .= "<font color=red>超过信用额度";
                    $waittime += 200;
                }
                else if ($limit[$bettype][1] < $money)
                {
                    $tmp .= "<font color=red>超过单注限额";
                    $waittime += 200;
                }
                else
                {
                    $n = Get_bet_amounts($bettype, $val);
                    if ($limit[$bettype][2] < $money + $n)
                    {
                        $tmp .= "<font color=red>超过下注限额";
                        $waittime += 200;
                    }
                    else if ($conf->get("waitbet") <= date("Hi"))
                    {
                        $tmp .= "<font color=red>已经截止下注";
                        $waittime += 200;
                    }
                    else
                    {
                        $stime = systime();
                        $p = array($bettype, $val);
                        if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                        {
                            $tmp .= "<font color=green>成功 ";
                            $usedamount += $money;
                            $limit[$bettype][2] += $money;
                            $total += $money;
                        }
                        else
                        {
                            $tmp .= "<font color=green>超过信用额度 ";
                            break;
                        }
                    }
                }
                $tmp .= "</font></td>";
            }
            else
            {
                echo "<input type=hidden name=r21[] value=\"" . $val . "\">";
                $total += $money;
            }
            $tmp .= "</tr>";
        }
    }
    ++$i;
}
$val = 1;
while ($val <= 10)
{
    if (isset($_POST["r22_" . $val]))
    {
        $money = intval($_POST["r22_" . $val]);
        $bettype = $bets == 1 ? 22 : 38;
        if (0 < $money)
        {
            if (!$ok)
            {
                echo "<input type=hidden name=r22_{$val} value=" . $money . ">";
            }
            ++$betcount;
            $err = 0;
            $tmp .= "<tr class=td2>";
            $tmp .= "<td>" . $g_betname[$bettype] . "</td>";
            $tmp .= "<td>" . $val . "</td>";
            if ($val == 0)
            {
                $val = 10;
            }
            $sub_rates = get_subs_rates($u5['id'], $lotto_id, 22, $val);
            $rate = $rates->f["r{$bettype}_" . $val] - $sub_rates;
            $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
            $tmp .= "<td align=right>" . $money . "</td>";
            if ($ok)
            {
                $tmp .= "<td>";
                if ($money < $betmin)
                {
                    $tmp .= "<font color=red>小於最小限额";
                    $waittime += 200;
                }
                else if ($curruser['amount'] < $money + $usedamount)
                {
                    $tmp .= "<font color=red>超过信用额度";
                    $waittime += 200;
                }
                else if ($limit[$bettype][1] < $money)
                {
                    $tmp .= "<font color=red>超过单注限额";
                    $waittime += 200;
                }
                else
                {
                    $n = Get_bet_amounts($bettype, $val);
                    if ($limit[$bettype][2] < $money + $n)
                    {
                        $tmp .= "<font color=red>超过下注限额";
                        $waittime += 200;
                    }
                    else if ($conf->get("waitbet") <= date("Hi"))
                    {
                        $tmp .= "<font color=red>已经截止下注";
                        $waittime += 200;
                    }
                    else
                    {
                        $stime = systime();
                        if ($val == 0)
                        {
                            $val = 10;
                        }
                        $p = array($bettype, $val);
                        if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                        {
                            $tmp .= "<font color=green>成功 ";
                            $usedamount += $money;
                            //$limit[$bettype] += 2;
                            $total += $money;
                        }
                        else
                        {
                            $tmp .= "<font color=green>超过信用额度 ";
                            break;
                        }
                    }
                }
                $tmp .= "</font></td>";
            }
            else
            {
                echo "<input type=hidden name=r22[] value=\"" . $val . "\">";
                $total += $money;
            }
            $tmp .= "</tr>";
        }
    }
    ++$val;
}
if (isset($_POST['rm344']))
{
    $money = intval($_POST['rm344']);
    if (0 < $money)
    {
        ++$betcount;
        $err = 0;
        $tmp .= "<tr class=td2>";
        $tmp .= "<td>总肖</td>";
        $tmp .= "<td>234</td>";
        $sub_rates = get_subs_rates($u5['id'], $lotto_id, 34, "4");
        $rate = $rates->f['r34_4'] - $sub_rates;
        $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
        $tmp .= "<td align=right>" . $money . "</td>";
        if ($ok)
        {
            $tmp .= "<td>";
            if ($money < $betmin)
            {
                $tmp .= "<font color=red>小於最小限额";
                $waittime += 200;
            }
            else if ($curruser['amount'] < $money + $usedamount)
            {
                $tmp .= "<font color=red>超过信用额度";
                $waittime += 200;
            }
            else if ($limit[34][1] < $money)
            {
                $tmp .= "<font color=red>超过单注限额";
                $waittime += 200;
            }
            else
            {
                $n = Get_bet_amounts(34, "4");
                if ($limit[34][2] < $money + $n)
                {
                    $tmp .= "<font color=red>超过下注限额";
                    $waittime += 200;
                }
                else if ($conf->get("waitbet") <= date("Hi"))
                {
                    $tmp .= "<font color=red>已经截止下注";
                    $waittime += 200;
                }
                else
                {
                    $stime = systime();
                    $p = array(34, "4");
                    if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                    {
                        $tmp .= "<font color=green>成功 ";
                        $usedamount += $money;
                        //$limit[34] += 2;
                        $total += $money;
                    }
                    else
                    {
                        $tmp .= "<font color=green>超过信用额度 ";
                        break;
                    }
                }
            }
            $tmp .= "</font></td>";
        }
        else
        {
            echo "<input type=hidden name=rm344 value=" . $money . ">";
            $total += $money;
        }
        $tmp .= "</tr>";
    }
}
if (isset($_POST['rm345']))
{
    $money = intval($_POST['rm345']);
    if (0 < $money)
    {
        ++$betcount;
        $err = 0;
        $tmp .= "<tr class=td2>";
        $tmp .= "<td>总肖</td>";
        $tmp .= "<td>5</td>";
        $sub_rates = get_subs_rates($u5['id'], $lotto_id, 34, "5");
        $rate = $rates->f['r34_5'] - $sub_rates;
        $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
        $tmp .= "<td align=right>" . $money . "</td>";
        if ($ok)
        {
            $tmp .= "<td>";
            if ($money < $betmin)
            {
                $tmp .= "<font color=red>小於最小限额";
                $waittime += 200;
            }
            else if ($curruser['amount'] < $money + $usedamount)
            {
                $tmp .= "<font color=red>超过信用额度";
                $waittime += 200;
            }
            else if ($limit[34][1] < $money)
            {
                $tmp .= "<font color=red>超过单注限额";
                $waittime += 200;
            }
            else
            {
                $n = Get_bet_amounts(34, "5");
                if ($limit[34][2] < $money + $n)
                {
                    $tmp .= "<font color=red>超过下注限额";
                    $waittime += 200;
                }
                else if ($conf->get("waitbet") <= date("Hi"))
                {
                    $tmp .= "<font color=red>已经截止下注";
                    $waittime += 200;
                }
                else
                {
                    $stime = systime();
                    $p = array(34, "5");
                    if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                    {
                        $tmp .= "<font color=green>成功 ";
                        $usedamount += $money;
                        //$limit[34] += 2;
                        $total += $money;
                    }
                    else
                    {
                        $tmp .= "<font color=green>超过信用额度 ";
                        break;
                    }
                }
            }
            $tmp .= "</font></td>";
        }
        else
        {
            echo "<input type=hidden name=rm345 value=" . $money . ">";
            $total += $money;
        }
        $tmp .= "</tr>";
    }
}
if (isset($_POST['rm346']))
{
    $money = intval($_POST['rm346']);
    if (0 < $money)
    {
        ++$betcount;
        $err = 0;
        $tmp .= "<tr class=td2>";
        $tmp .= "<td>总肖</td>";
        $tmp .= "<td>6</td>";
        $sub_rates = get_subs_rates($u5['id'], $lotto_id, 34, "6");
        $rate = $rates->f['r34_6'] - $sub_rates;
        $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
        $tmp .= "<td align=right>" . $money . "</td>";
        if ($ok)
        {
            $tmp .= "<td>";
            if ($money < $betmin)
            {
                $tmp .= "<font color=red>小於最小限额";
                $waittime += 200;
            }
            else if ($curruser['amount'] < $money + $usedamount)
            {
                $tmp .= "<font color=red>超过信用额度";
                $waittime += 200;
            }
            else if ($limit[34][1] < $money)
            {
                $tmp .= "<font color=red>超过单注限额";
                $waittime += 200;
            }
            else
            {
                $n = Get_bet_amounts(34, "6");
                if ($limit[34][2] < $money + $n)
                {
                    $tmp .= "<font color=red>超过下注限额";
                    $waittime += 200;
                }
                else if ($conf->get("waitbet") <= date("Hi"))
                {
                    $tmp .= "<font color=red>已经截止下注";
                    $waittime += 200;
                }
                else
                {
                    $stime = systime();
                    $p = array(34, "6");
                    if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                    {
                        $tmp .= "<font color=green>成功 ";
                        $usedamount += $money;
                        //$limit[34] += 2;
                        $total += $money;
                    }
                    else
                    {
                        $tmp .= "<font color=green>超过信用额度 ";
                        break;
                    }
                }
            }
            $tmp .= "</font></td>";
        }
        else
        {
            echo "<input type=hidden name=rm346 value=" . $money . ">";
            $total += $money;
        }
        $tmp .= "</tr>";
    }
}
if (isset($_POST['rm347']))
{
    $money = intval($_POST['rm347']);
    if (0 < $money)
    {
        ++$betcount;
        $err = 0;
        $tmp .= "<tr class=td2>";
        $tmp .= "<td>总肖</td>";
        $tmp .= "<td>7</td>";
        $sub_rates = get_subs_rates($u5['id'], $lotto_id, 34, "7");
        $rate = $rates->f['r34_7'] - $sub_rates;
        $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
        $tmp .= "<td align=right>" . $money . "</td>";
        if ($ok)
        {
            $tmp .= "<td>";
            if ($money < $betmin)
            {
                $tmp .= "<font color=red>小於最小限额";
                $waittime += 200;
            }
            else if ($curruser['amount'] < $money + $usedamount)
            {
                $tmp .= "<font color=red>超过信用额度";
                $waittime += 200;
            }
            else if ($limit[34][1] < $money)
            {
                $tmp .= "<font color=red>超过单注限额";
                $waittime += 200;
            }
            else
            {
                $n = Get_bet_amounts(34, "7");
                if ($limit[34][2] < $money + $n)
                {
                    $tmp .= "<font color=red>超过下注限额";
                    $waittime += 200;
                }
                else if ($conf->get("waitbet") <= date("Hi"))
                {
                    $tmp .= "<font color=red>已经截止下注";
                    $waittime += 200;
                }
                else
                {
                    $stime = systime();
                    $p = array(34, "7");
                    if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                    {
                        $tmp .= "<font color=green>成功 ";
                        $usedamount += $money;
                        $limit[34] += 2;
                        $total += $money;
                    }
                    else
                    {
                        $tmp .= "<font color=green>超过信用额度 ";
                        break;
                    }
                }
            }
            $tmp .= "</font></td>";
        }
        else
        {
            echo "<input type=hidden name=rm347 value=" . $money . ">";
            $total += $money;
        }
        $tmp .= "</tr>";
    }
}
if (isset($_POST['rm351']))
{
    $money = intval($_POST['rm351']);
    if (0 < $money)
    {
        ++$betcount;
        $err = 0;
        $tmp .= "<tr class=td2>";
        $tmp .= "<td>总肖</td>";
        $tmp .= "<td>单</td>";
        $sub_rates = get_subs_rates($u5['id'], $lotto_id, 35, "1");
        $rate = $rates->f['r35_1'] - $sub_rates;
        $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
        $tmp .= "<td align=right>" . $money . "</td>";
        if ($ok)
        {
            $tmp .= "<td>";
            if ($money < $betmin)
            {
                $tmp .= "<font color=red>小於最小限额";
                $waittime += 200;
            }
            else if ($curruser['amount'] < $money + $usedamount)
            {
                $tmp .= "<font color=red>超过信用额度";
                $waittime += 200;
            }
            else if ($limit[35][1] < $money)
            {
                $tmp .= "<font color=red>超过单注限额";
                $waittime += 200;
            }
            else
            {
                $n = Get_bet_amounts(35, "1");
                if ($limit[35][2] < $money + $n)
                {
                    $tmp .= "<font color=red>超过下注限额";
                    $waittime += 200;
                }
                else if ($conf->get("waitbet") <= date("Hi"))
                {
                    $tmp .= "<font color=red>已经截止下注";
                    $waittime += 200;
                }
                else
                {
                    $stime = systime();
                    $p = array(35, "1");
                    if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                    {
                        $tmp .= "<font color=green>成功 ";
                        $usedamount += $money;
                        //$limit[35] += 2;
                        $total += $money;
                    }
                    else
                    {
                        $tmp .= "<font color=green>超过信用额度 ";
                        break;
                    }
                }
            }
            $tmp .= "</font></td>";
        }
        else
        {
            echo "<input type=hidden name=rm351 value=" . $money . ">";
            $total += $money;
        }
        $tmp .= "</tr>";
    }
}
if (isset($_POST['rm352']))
{
    $money = intval($_POST['rm352']);
    if (0 < $money)
    {
        ++$betcount;
        $err = 0;
        $tmp .= "<tr class=td2>";
        $tmp .= "<td>总肖</td>";
        $tmp .= "<td>双</td>";
        $sub_rates = get_subs_rates($u5['id'], $lotto_id, 35, "2");
        $rate = $rates->f['r35_2'] - $sub_rates;
        $tmp .= "<td align=right>" . trimfloat($rate, 1) . "</td>";
        $tmp .= "<td align=right>" . $money . "</td>";
        if ($ok)
        {
            $tmp .= "<td>";
            if ($money < $betmin)
            {
                $tmp .= "<font color=red>小於最小限额";
                $waittime += 200;
            }
            else if ($curruser['amount'] < $money + $usedamount)
            {
                $tmp .= "<font color=red>超过信用额度";
                $waittime += 200;
            }
            else if ($limit[35][1] < $money)
            {
                $tmp .= "<font color=red>超过单注限额";
                $waittime += 200;
            }
            else
            {
                $n = Get_bet_amounts(35, "2");
                if ($limit[35][2] < $money + $n)
                {
                    $tmp .= "<font color=red>超过下注限额";
                    $waittime += 200;
                }
                else if ($conf->get("waitbet") <= date("Hi"))
                {
                    $tmp .= "<font color=red>已经截止下注";
                    $waittime += 200;
                }
                else
                {
                    $stime = systime();
                    $p = array(35, "2");
                    if (betin($p, $money, $rate, $sub_rates, $u2, $u3, $u4, $u5, $stime, $disk))
                    {
                        $tmp .= "<font color=green>成功 ";
                        $usedamount += $money;
                       // $limit[35] += 2;
                        $total += $money;
                    }
                    else
                    {
                        $tmp .= "<font color=green>超过信用额度 ";
                        break;
                    }
                }
            }
            $tmp .= "</font></td>";
        }
        else
        {
            echo "<input type=hidden name=rm352 value=" . $money . ">";
            $total += $money;
        }
        $tmp .= "</tr>";
    }
}
if ($betcount == 0)
{
    echo "<p><font color=red><b>请输入下注金额！</b></font></p>";
    echo "<p><input type=button value='回上一页' onclick='history.back()'></p>";
    exit();
}
echo "您下注的是：" . strtoupper($disk) . " 盘";
echo "<table border=0 cellpadding=2 cellspacing=1 class=table0>";
echo "<tr class=td0> <td>下注方式</td> <td>下注内容</td> <td>赔率</td> <td>下注金额</td>";
if ($ok)
{
    echo "<td>结果</td>";
}
echo "</tr>";
echo $tmp;
echo "<tr class=td0 align=right><td colspan=3>合计</td><td>" . $total . "</td>" . ( $ok ? "<td>&nbsp;</td>" : "" ) . "</tr>";
echo "</table>";
if ($ok)
{
    echo "<script>";
    echo "parent.leftFrame.location.href='op.php?op=member&fp=account';";
    echo "setTimeout(\"location.href='op.php?op=member&fp=bet9&bets={$bets}'\"," . $waittime . ");";
    echo "</script>";
}
else
{
    echo "<br>";
    echo "<input type=submit name=submit value=确定下注>&#12288;<input name=reset type=reset value=取消下注 onclick='history.back()'>";
    echo "</form>";
    echo "<Script>function StartFocus(){  document.forms[0].submit.focus();}</Script>";
    echo "</body>";
}
?>